package com.itcast.bihuan;

import com.itcast.util.ExcelUtils;
import com.itcast.util.JsonUtils;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/3/15 0015.
 */
public class GetJson {
    /**
     * 生成新建闭环的json文件
     * @param args
     */
    public static void main(String[] args){

        List<List<Object>>  list =  ExcelUtils.readExcelAll("C:\\Users\\Administrator\\Desktop\\杂物\\数据\\20160321数据.xlsx",1);
        String ffp = "e:/zuizhong";
        String fileName = "liyuan.json";
        File file = new File(ffp,fileName);
        int i = 0;
        //StringBuilder stringBuilder = new StringBuilder();
        for(List<Object> lis : list){
            //只取前5列的值
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("id", i);
            map.put("url", lis.get(0));
            map.put("contentSelector", lis.get(1));
            map.put("pageSelector", lis.get(2));
            map.put("nextButtonSelector", null);
            map.put("extractLimitNum", 10000);
            map.put("itemTagName", "a");
            map.put("nextPageUrlConvert", null);
            map.put("cron", "");
            map.put("finishUrl", null);
            map.put("append", false);
            map.put("enable", true);
            map.put("overwrite", true);
            map.put("description", "-");
            String str = JsonUtils.toJson(map);
            try {
                FileUtils.write(file, str, "UTF-8", true);
                FileUtils.write(file, ",", "UTF-8", true);
                FileUtils.write(file, "\r\n", "GBK", true);
            } catch (IOException e) {
                e.printStackTrace();
            }


            // System.out.println(str);
            i++;
            System.out.println(i);
        }

    }
}
